<?php
Prado::using('Application.common.common');
class ResetUserPassword extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		if (!$this->IsPostBack)
		{
			$this->Master->pageHead->Title = "Change User Password";
			$this->AdminMenu->lnkManageUser->CssClass = "active";
			
			if ($this->Request->contains('m')) {
				$this->Notice->Type = UserNoticeType::NoticeAdmin;
				if ($this->Request['m'] == 'uu')	
					$this->Notice->Text = $this->Application->getModule('message')->translate('UPDATE_SUCCESS','Password','');
				
			}
			
			$this->txtUserID->Value = ($this->Request->contains('uid')) ? TPropertyValue::ensureInteger($this->Request['uid']) : 0;	
			$userRecord = UserRecord::finder()->findByPk($this->txtUserID->Value);
			if ($userRecord instanceof UserRecord)
			{
				$this->lblUserName->Text=$userRecord->UserName;
				$this->lblUserEmail->Text=$userRecord->Email;			
			}
		}
	}
	
	protected function btnSubmit_Clicked($sender, $param)
	{
		if ($this->IsValid)
		{
			$user = UserRecord::finder()->findByPk($this->txtUserID->Value);
			if ($user instanceof UserRecord)
			{
				$user->Password = md5($this->txtNewPassword->SafeText);
				$user->save();
				//$this->Application->getModule("auth")->updateSessionUser($this->Application->User->createUser($user->Email));
				$this->Response->redirect($this->Service->ConstructUrl("admin.ResetUserPassword", array('uid'=>$user->ID,'m'=>'uu')));
			}
			else
			{
				$this->Notice->Type = UserNoticeType::Error;
				$this->Notice->Text = $this->Application->getModule('message')->translate('ITEM_NOT_FOUND','user');
			}
		}
	}
	
	protected function btnCancel_Clicked($sender, $param)
	{
		$this->Response->redirect($this->Service->ConstructUrl("admin.ManageUsers"));				
	}
}

?>